<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="ja">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>uupaa-detect.js - uuClass.Singleton test</title>
<style type="text/css">@import url(../README.css);</style>
<script type="text/javascript" src="../uupaa-detect.js"></script>
</head>
<body>
<input type="button" value="Run" onclick="Run()" />
<div id="log"></div>
<script>
function log(mix) {
  document.getElementById("log").innerHTML += "<br />" + mix;
}
function Run() {
  var MyClass = uuClass.Singleton();
  MyClass.prototype = {
    construct:  function() { log("call construct");  },
    stabled:    function() { log("call stabled");    },
    destruct:   function() { log("call destruct");   },
    method:     function() { log("call method");     }
  };
  var my = new MyClass();
  my.method();

  var my2 = new MyClass();
  my.method();

  log(my === my2); // "true"

  window.setTimeout(function() {
    if (window.confirm("jump to http://www.example.com/")) {
      window.location.href = "http://www.example.com/";
    }
  }, 1000);
}
</script>
<pre class="eg">
function Run() {
  var MyClass = <b>uuClass.Singleton</b>();
  MyClass.prototype = {
    <b>construct</b>:  function() { log("call construct");  },
    <b>stabled</b>:    function() { log("call stabled");    },
    <b>destruct</b>:   function() { log("call destruct");   },
    method:     function() { log("call method");     }
  };
  var my = new <b>MyClass</b>();
  my.method();

  var my2 = new <b>MyClass</b>(); <u>// 二度目のnew</u>
  my.method();

  log(my === my2); <u>// "true"  myとmy2は同じもの(シングルトン)</u>

  window.setTimeout(function() {
    if (window.confirm("jump to http://www.example.com/")) {
      <u>// ページ遷移が発生するため、自動的に destruct() を1度だけ実行する。</u>
      window.location.href = "http://www.example.com/";
    }
  }, 1000);
}
</pre>
</body></html>
